﻿/*
 * 由SharpDevelop创建。
 * 用户： LimitUser
 * 日期: 2013-1-16
 * 时间: 17:39
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using Microsoft.Win32;

namespace DotNet.Common
{
	/// <summary>
	/// Description of ShellOpenCommand.
	/// </summary>
	static public class ShellOpenCommand
	{
		/// <summary>
		/// 
		/// </summary>
		/// <param name="fileExt">eg. ".txt"</param>
		static public bool ReadCommandPath(string fileExt,out string commandPath)
		{
			commandPath = string.Empty;
			try
			{
				if(string.IsNullOrEmpty(fileExt))
					return false;
				
				RegistryKey key;
				key = Registry.ClassesRoot.OpenSubKey(fileExt);
				string fileType = (string)key.GetValue(string.Empty);
				if(string.IsNullOrEmpty(fileType))
					return false;
				
				key = Registry.ClassesRoot.OpenSubKey(fileType + @"\shell\open\command");
				commandPath = (string)key.GetValue(string.Empty);
				
				return !string.IsNullOrEmpty(commandPath);
			}
			catch
			{
				return false;
			}
		}
	}
}
